home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / libs / DateLib.lha / DateLib / Developer / C / examples / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-06  |  3.2 KB  |  93 lines

  1.  /* Copyright © 1999 Dipl.-Inform. Kai Hofmann. All rights reserved. */
  2.  
  3.  
  4.  #ifndef DEBUG_H
  5.    #define DEBUG_H
  6.  
  7.  
  8.    #include <exec/types.h>
  9.    #include <string.h>
  10.  
  11.  
  12.    void debug_inc_nest_level(void);
  13.    void debug_dec_nest_level(void);
  14.    void debug_print_nest(void);
  15.  
  16.  
  17.    #ifdef DEBUG
  18.  
  19.      void __far kprintf(UBYTE *fmt, ...);
  20.      /* void dprintf(UBYTE *fmt,...); */
  21.  
  22.      /* Left in beta release */
  23.      #define DEBUG_PRINT_NEST        kprintf("  ");
  24.      #define DEBUG_PCHECK(cond)        if (!(cond)) {debug_print_nest(); kprintf("PCHECK: %s:%5lu " #cond "\n",__FILE__,(unsigned long)__LINE__);}
  25.  
  26.      #if DEBUG > 1
  27.        /* No output in normal code path */
  28.        #define DEBUG_ASSERT(cond)    if (!(cond)) {debug_print_nest(); kprintf("ASSERT: %s:%5lu " #cond "\n",__FILE__,(unsigned long)__LINE__);}
  29.  
  30.        #if DEBUG > 2
  31.          /* Very basic output */
  32.          /* enter/exit output + parameters/return */
  33.          #define DEBUG_ENTER(name)        debug_print_nest(); kprintf("ENTER : %s:%5lu %s()\n",__FILE__,(unsigned long)__LINE__,name); debug_inc_nest_level();
  34.          #define DEBUG_EXIT(name,fmt,ret_val)    debug_dec_nest_level(); debug_print_nest(); kprintf("EXIT  : %s:%5lu %s()%s" fmt "\n",__FILE__,(unsigned long)__LINE__,name,(strlen(fmt) != 0) ? " -> " : "",ret_val);
  35.          #define DEBUG_VARDUMP(name,fmt,val)    debug_print_nest(); kprintf("%s=" fmt "\n",name,val);
  36.          #define DEBUG_POS            debug_print_nest(); kprintf(stderr,"POS: %s:%5lu\n",__FILE__,(unsigned long)__LINE__);
  37.  
  38.          #if DEBUG > 3
  39.            /* Moderate output */
  40.            /* debug output for ANSI C/C++ functions */
  41.            #define DEBUG_ALLOC(name,adr,size)    debug_print_nest(); kprintf("MALLOC: %s=%lx, %lu\n",name,adr,size);
  42.            #define DEBUG_FREE(name,adr)        debug_print_nest(); kprintf("FREE: %s=%lx\n",name,adr);
  43.  
  44.            #if DEBUG > 4
  45.              /* Verbose output */
  46.              /* TestAll(heap,stack,null,freespace) */
  47.            #else
  48.              /* No verbose output */
  49.            #endif
  50.          #else
  51.            #define DEBUG_ALLOC(name,adr,size)
  52.            #define DEBUG_FREE(name,adr)
  53.            /* No moderate output */
  54.            /* No verbose output */
  55.          #endif
  56.        #else
  57.          /* No basic output */
  58.          #define DEBUG_ENTER(name)
  59.          #define DEBUG_EXIT(name,fmt,ret_val)
  60.          #define DEBUG_VARDUMP(name,fmt,val)
  61.          #define DEBUG_ALLOC(name,adr,size)
  62.          #define DEBUG_FREE(name,adr)
  63.          /* No moderate output */
  64.          /* No verbose output */
  65.        #endif
  66.      #else
  67.        /* No output in normal code path */
  68.        #define DEBUG_PRINT_NEST
  69.        #define DEBUG_ASSERT(cond)
  70.        #define DEBUG_ENTER(name)
  71.        #define DEBUG_EXIT(name,fmt,ret_val)
  72.        #define DEBUG_VARDUMP(name,fmt,val)
  73.        #define DEBUG_ALLOC(name,adr,size)
  74.        #define DEBUG_FREE(name,adr)
  75.        /* No moderate output */
  76.        /* No verbose output */
  77.      #endif
  78.    #else
  79.      /* No debugging */
  80.      #define DEBUG_PRINT_NEST
  81.      #define DEBUG_PCHECK(cond)
  82.      #define DEBUG_ASSERT(cond)
  83.      #define DEBUG_ENTER(name)
  84.      #define DEBUG_EXIT(name,fmt,ret_val)
  85.      #define DEBUG_VARDUMP(name,fmt,val)
  86.      #define DEBUG_ALLOC(name,adr,size)
  87.      #define DEBUG_FREE(name,adr)
  88.      /* No moderate output */
  89.      /* No verbose output */
  90.    #endif
  91.  
  92.  #endif
  93.